package com.dis.insurance.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.insurance.service.InsureService;
import com.dis.pojo.dto.InsureDTO;
import com.dis.pojo.queryDTO.InsurePageQueryDTO;
import com.dis.pojo.vo.InsureVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/insure")
@Api(tags = "病人信息管理接口")
@Slf4j
public class InsureController {

    @Autowired
    private InsureService insureService;

    @PostMapping
    @ApiOperation("新增病人")
    @CheckPermission("patient:add")
    public Result save(@RequestBody InsureDTO insureDTO) {
        log.info("新增病人：{}", insureDTO);
        insureService.save(insureDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("病人分页查询")
    @CheckPermission("patient:query")
    public Result<PageResult> page(InsurePageQueryDTO insurePageQueryDTO) {
        log.info("病人分页查询：{}", insurePageQueryDTO);
        PageResult pageResult = insureService.pageQuery(insurePageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询病人")
    @CheckPermission("patient:query")
    public Result<InsureVO> getById(@PathVariable Long id) {
        log.info("根据id查询病人：{}", id);
        InsureVO insureVO = insureService.getById(id);
        return Result.success(insureVO);
    }

    @PutMapping
    @ApiOperation("修改病人信息")
    @CheckPermission("patient:edit")
    public Result update(@RequestBody InsureDTO insureDTO) {
        log.info("修改病人信息：{}", insureDTO);
        insureService.update(insureDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除病人")
    @CheckPermission("patient:delete")
    public Result delete(@PathVariable Long id) {
        log.info("删除病人：{}", id);
        insureService.delete(id);
        return Result.success();
    }

}
